import time

from common.Utils import FSDriver
from selenium.webdriver.common.by import By


# 主页面
class Mainpage:
    url = ""
    driver = ""

    def __init__(self):
        self.url = "http://127.0.0.1:58080/index.html"
        self.driver = FSDriver.driver
        self.driver.get(self.url)
        self.driver.implicitly_wait(5)

    # 帖子目录
    def directory_of_posts(self):
        assert self.driver.find_element(By.CSS_SELECTOR,
                                        "#bit-forum-content > div.page-header.d-print-none > div > div")
        assert self.driver.find_element(By.CSS_SELECTOR, "#artical-items-body > div:nth-child(1)")
        assert self.driver.find_element(By.CSS_SELECTOR,
                                        "#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col > ul")
        assert self.driver.find_element(By.CSS_SELECTOR,
                                        '#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(1)')
        assert self.driver.find_element(By.CSS_SELECTOR,
                                        '#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(2)')
        assert self.driver.find_element(By.CSS_SELECTOR,
                                        '#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(3)')

    # 主页->首页
    def directory_homepage(self):
        self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index").click()

        FSDriver.getscreeshot()
        assert self.driver.find_element(By.CSS_SELECTOR, "#article_list_board_title")
        self.directory_of_posts()

    # 主页->java
    def directory_java(self):
        self.driver.find_element(By.CSS_SELECTOR, '#topBoardList > li:nth-child(2)').click()

        FSDriver.getscreeshot()
        self.directory_of_posts()

    # 主页->C++
    def directory_cpp(self):
        self.driver.find_element(By.CSS_SELECTOR, '#topBoardList > li:nth-child(3) > a').click()

        FSDriver.getscreeshot()
        self.directory_of_posts()

    # 主页->前端
    def directory_web(self):
        self.driver.find_element(By.CSS_SELECTOR, '#topBoardList > li:nth-child(4) > a').click()

        FSDriver.getscreeshot()
        self.directory_of_posts()

    # 主页->MySQL
    def directory_mysql(self):
        self.driver.find_element(By.CSS_SELECTOR, '#topBoardList > li:nth-child(5) > a').click()

        FSDriver.getscreeshot()
        self.directory_of_posts()

    # 主页->面试宝典
    def directory_msbd(self):
        self.driver.find_element(By.CSS_SELECTOR, '#topBoardList > li:nth-child(6) > a').click()

        FSDriver.getscreeshot()
        self.directory_of_posts()

    # 主页->经验分享
    def directory_jyfx(self):
        self.driver.find_element(By.CSS_SELECTOR, '#topBoardList > li:nth-child(7) > a').click()

        FSDriver.getscreeshot()
        self.directory_of_posts()

    # 主页->招聘信息
    def directory_zpxx(self):
        self.driver.find_element(By.CSS_SELECTOR, '#topBoardList > li:nth-child(8) > a').click()

        FSDriver.getscreeshot()
        self.directory_of_posts()

    # 主页->福利待遇
    def directory_fldy(self):
        self.driver.find_element(By.CSS_SELECTOR, '#topBoardList > li:nth-child(9) > a').click()

        FSDriver.getscreeshot()
        self.directory_of_posts()

    # 主页->灌水区
    def directory_gsq(self):
        self.driver.find_element(By.CSS_SELECTOR, '#topBoardList > li:nth-child(10) > a').click()

        FSDriver.getscreeshot()
        self.directory_of_posts()

    # 目录栏
    def directory_col(self):
        # 是否是该页面
        assert self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar")
        self.directory_homepage()
        self.directory_java()
        self.directory_cpp()
        self.directory_web()
        self.directory_mysql()
        self.directory_msbd()
        self.directory_jyfx()
        self.directory_zpxx()
        self.directory_fldy()
        self.directory_gsq()

    # 目录->查找框
    def head_find(self):
        self.driver.find_element(By.CSS_SELECTOR,
                                 "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input").clear()
        self.driver.find_element(By.CSS_SELECTOR,
                                 "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input").send_keys('测试')

    # 夜晚模式
    def head_dark(self):
        self.directory_col()

        # 切换到夜晚模式
        self.driver.find_element(By.CSS_SELECTOR,
                                 'body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-dark > svg').click()
        dark_color = 'http://127.0.0.1:58080/index.html?theme=dark'
        assert self.driver.current_url == dark_color
        FSDriver.getscreeshot()

    # 白天模式
    def head_light(self):
        self.directory_col()

        self.driver.find_element(By.CSS_SELECTOR,
                                 'body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-light > svg').click()
        light_color = 'http://127.0.0.1:58080/index.html?theme=light'
        assert self.driver.current_url == light_color
        FSDriver.getscreeshot()

    # 头部栏
    def head_col(self):
        # 是否是该页面
        assert self.driver.find_element(By.CSS_SELECTOR,
                                        "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none")
        self.head_find()
        self.head_dark()
        self.head_light()






